import express from 'express'
import { parse } from 'url'
import cors from 'cors'

import vipLogin from './data/vip_login.json' assert { type: 'json' }
import adminLogin from './data/admin_login.json' assert { type: 'json' }
import adminPermission from './data/admin_permission.json' assert { type: 'json' }
import vipPermission from './data/vip_permission.json' assert { type: 'json' }

let app = express()

// Use cors middleware
app.use(cors())

app.get('/login', (req, res) => {
  const user = parse(req.url, true).query.user
  user === 'admin' ? res.send(adminLogin) : res.send(vipLogin)
})
app.get('/permission', (req, res) => {
  console.log(req, 'reqqqqqq')
  const user = parse(req.url, true).query.user
  user === 'admin' ? res.send(adminPermission) : res.send(vipPermission)
})

app.listen(3300, () => {
  console.log('Server is running on port 3300')
})
